package com.zhuozhou.jdyc.main.meinfo.adapter;

import android.content.Context;
import android.view.View;

import com.zhuozhou.jdyc.R;
import com.zhuozhou.jdyc.base.BaseRecyclerViewAdapter;
import com.zhuozhou.jdyc.base.BaseViewHolder;
import com.zhuozhou.jdyc.databinding.AdapterOrderBinding;
import com.zhuozhou.jdyc.main.meinfo.bean.BasicsMyPayBean;
import com.zhuozhou.jdyc.wight.recyclerview.MyLayoutManager;

/**
 * Create by CherishTang on 2020/3/27 0027
 * describe:首页菜单adapter
 */
public class OrderAdapter extends BaseRecyclerViewAdapter<BasicsMyPayBean.ListBeanX, AdapterOrderBinding> {
    private int type;
    private Boolean isRemind = false;
    public OnItemButtonClickListener mOnItemButtonClickListener;

    public OrderAdapter(Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.adapter_order;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder baseViewHolder, int pos) {
        super.onBindViewHolder(baseViewHolder, pos);
    }

    @Override
    public void onBindHolder(BaseViewHolder<AdapterOrderBinding> holder, int pos) {
        if (isRemind)
            holder.getBinding().tvRemindDelivery.setVisibility(View.GONE);
        else
            holder.getBinding().tvRemindDelivery.setVisibility(View.VISIBLE);
        holder.getBinding().setOrder(mList.get(pos));
        holder.getBinding().setType(type);
        OrderItemAdapter orderItemAdapter = new OrderItemAdapter(mContext);
        orderItemAdapter.setInfo(Integer.parseInt(mList.get(pos).getShoppingtype()), Integer.parseInt(mList.get(pos).getStatus()), Integer.parseInt(mList.get(pos).getUsertype()));
        orderItemAdapter.setList(mList.get(pos).getList());
        orderItemAdapter.setOnItemButtonClickListener((pos1, type) -> {
            if (mOnItemButtonClickListener != null)
                mOnItemButtonClickListener.OnItemButtonClick(pos1, pos, type);
        });
        holder.getBinding().mRecyclerViewGoods.setAdapter(orderItemAdapter);
        holder.getBinding().mRecyclerViewGoods.setLayoutManager(new MyLayoutManager(mContext));
        holder.getBinding().tvEvaluation.setOnClickListener(v -> {
            if (mOnItemButtonClickListener != null)
                mOnItemButtonClickListener.OnItemButtonClick(null, pos, 0);
        });
        holder.getBinding().tvBuyAgain.setOnClickListener(v -> {
            if (mOnItemButtonClickListener != null)
                mOnItemButtonClickListener.OnItemButtonClick(null, pos, 1);
        });
        holder.getBinding().tvCancelOrder.setOnClickListener(v -> {
            if (mOnItemButtonClickListener != null)
                mOnItemButtonClickListener.OnItemButtonClick(null, pos, 2);
        });
        holder.getBinding().tvPayment.setOnClickListener(v -> {
            if (mOnItemButtonClickListener != null)
                mOnItemButtonClickListener.OnItemButtonClick(null, pos, 3);
        });
        holder.getBinding().tvRemindDelivery.setOnClickListener(v -> {
            if (mOnItemButtonClickListener != null)
                mOnItemButtonClickListener.OnItemButtonClick(null, pos, 4);
        });
        holder.getBinding().tvCheckDelivery.setOnClickListener(v -> {
            if (mOnItemButtonClickListener != null)
                mOnItemButtonClickListener.OnItemButtonClick(null, pos, 5);
        });
        holder.getBinding().tvConfirmReceipt.setOnClickListener(v -> {
            if (mOnItemButtonClickListener != null)
                mOnItemButtonClickListener.OnItemButtonClick(null, pos, 6);
        });
    }

    public void setType(int type) {
        this.type = type;
    }

    public void setRemindDelivery() {
        this.isRemind = true;
        notifyDataSetChanged();
    }

    public void setOnItemButtonClickListener(OnItemButtonClickListener l) {
        mOnItemButtonClickListener = l;
    }

    public interface OnItemButtonClickListener {
        void OnItemButtonClick(Integer itemPos, int pos, int type);
    }
}
